package com.itheima.controller.admin;

import com.itheima.common.entity.Result;
import com.itheima.pojo.ImportEntity;
import com.itheima.pojo.MemberDateVo;
import com.itheima.pojo.SetMealDateVo;
import com.itheima.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/report")
@Slf4j
@Api(tags = "统计数据管理")
@RequiredArgsConstructor
public class ReportController {
    private final ReportService reportService;
    @ApiOperation("运营报表")
    @RequestMapping("/getSetmealReport")
    public Result getSetmealReport() {
      Result result = new Result();
      try {
          SetMealDateVo setMealDateVo = reportService.getSetmealReport();
          result.setData(setMealDateVo);
      } catch (Exception e) {
          throw new RuntimeException(e);
      }
      result.setFlag(true);
      result.setMessage("获取套餐统计数据成功");
      return result;
    }

    @ApiOperation("会员数量统计")
    @RequestMapping("/getMemberReport")
    public Result getMemberReport() {
        Result result = new Result();
        try {
            MemberDateVo memberDateVos = reportService.getMemberReport();
            result.setData(memberDateVos);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        result.setFlag(true);
        result.setMessage("获取会员数量统计数据成功");
        return result;
    }

    @ApiOperation("获取运营统计数据")
    @GetMapping("/getBusinessReportData")
    public Result getBusinessReport() {
        Result result = new Result();
        try {
           ImportEntity importEntity = reportService.getBusinessReport();
           result.setData(importEntity);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        result.setFlag(true);
        result.setMessage("获取运营统计数据成功");
        return result;
    }
    @GetMapping("/exportBusinessReport")
    @ApiOperation("导出运营数据")
    public String exportBusinessReport(HttpServletResponse response){
        log.info("导出运营数据");
        reportService.exportBusinessReport(response);
        return "下载文件";

    }
}
